/*
 * @Author: liqiang liqiang@hacint.com.cn
 * @Date: 2023-08-19 18:02:14
 * @LastEditors: liqiang liqiang@hacint.com.cn
 * @LastEditTime: 2023-08-19 20:09:21
 * @FilePath: \USERf:\WorkTest\WireTest4096\PIM4096MotherBoard\WireTest4096 V1.01.01\MidWare\PCCommand\PCCommand.c
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/**
 * @file PCCommand.c
 * @author liqiang (liqiang@hacint.com.cn)
 * @brief 
 * @version 1.0.0
 * @date 2023-08-19
 * 
 * 
 */

#include "PCCommand.h" 





/*测试*/
 
#include "unity.h"






static  PCCMD_StateTypeDef  pcCmdArry[32]= {
                                    PC_CMD_SCAN_START,               /*1*/
                                    PC_CMD_SCAN_ACCESSORY_START,     /*2*/
                                    PC_CMD_ALL_SCAN_STOP,           /*3*/
                                    PC_CMD_SELFCHECK,               /*4*/
                                    PC_CMD_SELFCHECK_QUICK,         /*5*/
                                    PC_CMD_READ_ENDPIN_FREE,        /*6*/
                                    PC_CMD_READ_ENDPIN_CURRENT,     /*7*/
                                    PC_CMD_SCAN_EMPTY_START_PIN,    /*8*/
                                    PC_CMD_SCAN_ENDPIN,              /*9*/
                                    PC_CMD_RESET_DATA,              /*10*/
                                    PC_CMD_RESET_PHY_PIN,           /*11*/
                                    PC_CMD_RESET_ALL,               /*12*/
                                    PC_CMD_SCAN_PROBE,              /*13*/
                                    PC_CMD_READ_DATA_TOTAL_COMPRESS,/*14*/    
                                    PC_CMD_SET_ONE_PIN_OR_ONE_LOOP,  /*15*/
                                    PC_CMD_SCAN_LED_START_PIN};      /*16*/        







unsigned        char    getBit32(unsigned int num,unsigned char i){
        
        if(i>=31){
                i = 31;
        }

        if((num>>i)&0x01){
                return  1;
        }else{
                return 0;
        }
}



unsigned        char  CovertPCCmdFromInt(unsigned int intCmd,\
                                        PCCMD_StateTypeDef* enumCmd){ 

        PCCMD_StateTypeDef eCmd;
        unsigned        char    i=0;
        unsigned        char    ret=0;  

        for(i=31;i>=0;i--){
                if(1==getBit32(intCmd,i)){
                       *enumCmd  =    pcCmdArry[i];     
                        return  ret     =       1;
                } 
        } 
        return  ret ; 
}
 



 
 
 
 
 
 
 
 
 
 
 /**
  * @brief unity test function
  * 
  */
 
 
void	Test_Get_Bit32(void){ 
        TEST_ASSERT_EQUAL_HEX8(0,getBit32(0x00000000,0)); 
        TEST_ASSERT_EQUAL_HEX8(0,getBit32(0x00000000,2)); 
        TEST_ASSERT_EQUAL_HEX8(0,getBit32(0x00000000,4)); 
        TEST_ASSERT_EQUAL_HEX8(0,getBit32(0x00000000,6)); 
        TEST_ASSERT_EQUAL_HEX8(0,getBit32(0x00000000,8)); 
        TEST_ASSERT_EQUAL_HEX8(0,getBit32(0x00000000,10)); 
        TEST_ASSERT_EQUAL_HEX8(0,getBit32(0x00000000,12)); 
        TEST_ASSERT_EQUAL_HEX8(0,getBit32(0x00000000,14));  

        TEST_ASSERT_EQUAL_HEX8(1,getBit32(0xFFFFFFFF,1)); 
        TEST_ASSERT_EQUAL_HEX8(1,getBit32(0xFFFFFFFF,3)); 
        TEST_ASSERT_EQUAL_HEX8(1,getBit32(0xFFFFFFFF,5)); 
        TEST_ASSERT_EQUAL_HEX8(1,getBit32(0xFFFFFFFF,7));
        TEST_ASSERT_EQUAL_HEX8(1,getBit32(0xFFFFFFFF,9)); 
        TEST_ASSERT_EQUAL_HEX8(1,getBit32(0xFFFFFFFF,11)); 
        TEST_ASSERT_EQUAL_HEX8(1,getBit32(0xFFFFFFFF,13)); 
        TEST_ASSERT_EQUAL_HEX8(1,getBit32(0xFFFFFFFF,15));            
}
 
void    TEST_CONVERT_PCCMD_FROM_INT(void){

        PCCMD_StateTypeDef enumCmd     ;
        unsigned        int     ret=0;

        //ret = CovertPCCmdFromInt(0X0001,&enumCmd)       ;
        TEST_ASSERT_TRUE(ret = CovertPCCmdFromInt(0X0001,&enumCmd) ); 
        TEST_ASSERT_TRUE(PC_CMD_SCAN_START == enumCmd );
        TEST_ASSERT_TRUE(ret = CovertPCCmdFromInt(0X0002,&enumCmd) ); 
        TEST_ASSERT_TRUE(PC_CMD_SCAN_ACCESSORY_START == enumCmd );
         TEST_ASSERT_TRUE(ret = CovertPCCmdFromInt(0X4000,&enumCmd) ); 
        TEST_ASSERT_TRUE(PC_CMD_SET_ONE_PIN_OR_ONE_LOOP == enumCmd );
        TEST_ASSERT_TRUE(ret = CovertPCCmdFromInt(0X8000,&enumCmd) ); 
        TEST_ASSERT_TRUE(PC_CMD_SCAN_LED_START_PIN == enumCmd );  

}
 
 
 
 
 
 
 
 
 
 
 
 



